/* 我的分公司二审 */
<template>
  <div>
    <Card :bordered="false">
      <p slot="title">分公司二审</p>
      <MyTrialTab :info="info" />
      <table id="Fgsershen" style="margin-bottom: 20px" width='100%' border="1" cellspacing="0" cellpadding="0">
        <tr>
          <th colspan="4">
            分公司二审单
          </th>
        </tr>
        <tr>
          <td width="25%">
            分公司二审人员
          </td>
          <td width="25%">{{info.audit2}}</td>
          <td width="25%">
            分公司二审时间
          </td>
          <td width="25%">
            {{this.$moment().format('YYYY-MM-DD')}}
          </td>
        </tr>
        <tr>
          <td colspan="4">
            <div style="width:99%;margin:auto;height:100%;">
              <Table highlight-row border ref="selection" :columns="ershenColumns" :data="info.Ershen" :loading="ershenLoading"
                @on-row-click="getIndex"></Table>
              <Row>
                <Col span="24" style="text-align: center;padding:10px">
                <Button type="primary" @click="inputAdd('Ershen')">添加</Button>
                <Button type="error" @click="inputRemove('Ershen')">删除</Button>
                </Col>
              </Row>
            </div>
          </td>
        </tr>
        <tr>
          <td>
            报告（正文、附图、附件、附表）
          </td>
          <td colspan="3">
            <Upload action="//jsonplaceholder.typicode.com/posts/">
              <Button>上传</Button>
            </Upload>
          </td>
        </tr>
      </table>
      <Row style="margin-top: 10px">
        <Col span="24" style="text-align:right;">
        <Button type="primary" @click="submit">发送意见</Button>
        </Col>
      </Row>
    </Card>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        info: {},
        ershenLoading: true,
        ershenColumns: [{
            align: "center",
            title: "序号",
            type: "index",
            width: 80
          },
          {
            align: "center",
            title: "分公司二审意见",
            key: "Audit_opinion",
            render: (h, {
              row,
              index
            }) => {
              return h("Input", {
                props: {
                  type: "text",
                  value: row.Audit_opinion
                },
                on: {
                  "on-blur": val => {
                    this.info.Ershen[index].Audit_opinion = val.target.value;
                  }
                }
              });
            }
          }
        ],
        query: [],
      };
    },
    mounted() {
      let query = this.$route.query;
      this.query = query;
      this.findByProject(query.Project_id, query.Atype);
    },
    methods: {
      //点击添加意见
      inputAdd(type) {
        this.info[type].push({});
      },
      inputRemove(type) {
        this.info[type].splice(this.allIndex, 1);
        console.log(this.info[type] + ' 被删除了')
      },
      getIndex(data, index, event) {
        this.allIndex = index;
      },
      //获取当前项目
      findByProject(Project_id, Atype) {
        axios
          .get("/audit/findByProject", {
            params: {
              Atype,
              Project_id
            }
          })
          .then(res => {
            console.log(res);
            this.info = res;
            this.ershenLoading = false;
          });
      },
      submit() {
        let query = this.query;
        let AuditReplyLists = this.info.Ershen;
        for (let val of AuditReplyLists) {
          val["Audit_id"] = query.id;
          val["Audit_time"] = this.$moment().format("YYYY-MM-DD HH:mm:ss");
        }
        if (Object.keys(AuditReplyLists).length <= 0) {
          this.$Modal.error({
            title: "点击添加请输入意见"
          });
        } else {
          axios
            .get("/audit/isAuditb", {
              params: {
                Project_id: query.Project_id,
                Btype: query.Atype,
                OK: 1
              }
            })
            .then(res => {
              let title = res._MESSAGE;
              if (res._STATUS == 1) {
                this.$Modal.success({
                  title: title + ": 请进入正在进行项目人员提交"
                });
                axios
                  .post("/auditreply/saveOrUpdateM", {
                    AuditReplyLists
                  })
                  .then(res => {})
                  .catch(err => {
                    this.$Modal.error({
                      title: "发送失败"
                    });
                  });
              } else {
                this.$Modal.error({
                  title: title + "：等待业务人员提交"
                });
              }
            });
        }
      }
    }
  };
</script>
<style lang="less">
  #Fgsershen {
    .ivu-input {
      border: none !important;
      height: 30px;

      input {
        outline: medium;
      }
    }
  }
</style>